package com.lg.erp.controller.jml;


import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.jml.TPost;
import com.lg.erp.mapper.jml.TPostMapper;
import com.lg.erp.service.jml.ITPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@RestController
public class TPostController {

    @Autowired
    private TPostMapper postMapper;

    @Autowired
    private ITPostService postService;

    @GetMapping("/posts/{id}")
    public JsonResult selectAllPost(@PathVariable String id){
        List<TPost> post = postMapper.selectAll(id);
        return new JsonResult(1,"ok",post);
    }

    @PostMapping("/posts/{id}/{name}")
    public JsonResult addPost(@PathVariable String id,@PathVariable String name){
        TPost post = new TPost();
        post.setId(UUID.randomUUID().toString().substring(0,6));
        post.setDId(id);
        post.setName(name);
        postService.save(post);
        return new JsonResult(1,"ok",null);
    }
}
